public class findMedianSortedArrays {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int a = nums1.length;
        int b = nums2.length;
        int left = 0;
        int right = 0;
        int index1 = 0;
        int index2 = 0;
        for(int i = 0; i <= (a + b)/2; i++){
            left = right;
            if (index1 < a && (index2 >= b || nums1[index1] <= nums2[index2])){
                right = nums1[index1];
                index1++;
            }else{
                right = nums2[index2];
                index2++;
            }
        }
        if((a + b) % 2 == 0){
            return(left + right)/2.0;
        }else{
            return right;
        }
    }
}
